package com.tuo51.manager.controller;


import com.tuo51.childcare.service.BizEvaluateImportService;
import com.tuo51.core.service.StaffService;
import com.tuo51.evaluate.service.ImportService;
import com.tuo51.foudation.model.ErrorCode;
import com.tuo51.foudation.model.MemVerificationCache;
import com.tuo51.foudation.model.StatusResponse;
import com.tuo51.manager.domain.SysUser;
import com.tuo51.observation.service.ObImportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import static com.tuo51.foudation.constant.RequestConstant.APP_CHANNEL;
import static com.tuo51.foudation.constant.RequestConstant.TICKET;

/**
 * 附近的合作伙伴
 */
@RestController
@RequestMapping("/mapi/import")
@Api(value = "/mapi/import", tags = "OP - 数据导入")
public class MAPIImportController {
    @Autowired
    private MemVerificationCache cache;

    @Autowired
    private StaffService staffService;

    @Autowired
    private ImportService importService;

    @Autowired
    private ObImportService obImportService;

    @Autowired
    private BizEvaluateImportService bizImportService;

    @ApiOperation(value = "导入儿心量表问题列表",httpMethod = "POST")
    @RequestMapping(value = "/import_question", method = RequestMethod.POST, headers="content-type=multipart/form-data")
    public StatusResponse importQuestion(@RequestHeader(TICKET) String ticket, @RequestParam(value = "file", required = false) MultipartFile file) {
        SysUser sysUser = cache.getSysUser(ticket);
        if (sysUser != null){
            return StatusResponse.success(importService.importQuestion(file));
        }
        return StatusResponse.error(ErrorCode.STAFF_HAS_NO_ROLE, "需要管理员");
    }

    @ApiOperation(value = "导入儿心量表高级报告信息",httpMethod = "POST")
    @RequestMapping(value = "/import_highlevel_info", method = RequestMethod.POST, headers="content-type=multipart/form-data")
    public StatusResponse importHighLevelInfo(@RequestHeader(TICKET) String ticket, @RequestParam(value = "file", required = false) MultipartFile file) {
        SysUser sysUser = cache.getSysUser(ticket);
        if (sysUser != null){
            return StatusResponse.success(importService.importHighLevelInfo(file));
        }
        return StatusResponse.error(ErrorCode.STAFF_HAS_NO_ROLE, "需要管理员");
    }

    @ApiOperation(value = "更新儿心量表高级报告信息，能力拓展+相关视频, 张锋给的模板文件。",httpMethod = "POST")
    @RequestMapping(value = "/import_highlevel_info_20220426", method = RequestMethod.POST, headers="content-type=multipart/form-data")
    public StatusResponse importHighLevelInfo20220426(@RequestHeader(TICKET) String ticket, @RequestParam(value = "file", required = false) MultipartFile file) {
        SysUser sysUser = cache.getSysUser(ticket);
        if (sysUser != null){
            return StatusResponse.success(importService.importHighLevelInfo(file));
        }
        return StatusResponse.error(ErrorCode.STAFF_HAS_NO_ROLE, "需要管理员");
    }

    @ApiOperation(value = "导入儿心量表问题的标签关系",httpMethod = "POST")
    @RequestMapping(value = "/import_question_tags", method = RequestMethod.POST, headers="content-type=multipart/form-data")
    public StatusResponse importQuestionTags(@RequestHeader(TICKET) String ticket, @RequestParam(value = "file", required = false) MultipartFile file) {
        SysUser sysUser = cache.getSysUser(ticket);
        if (sysUser != null){
            return StatusResponse.success(importService.importQuestionTags(file));
        }
        return StatusResponse.error(ErrorCode.STAFF_HAS_NO_ROLE, "需要管理员");
    }

    @ApiOperation(value = "导入分类视频",httpMethod = "POST")
    @RequestMapping(value = "/import_videos", method = RequestMethod.POST, headers="content-type=multipart/form-data")
    public StatusResponse importVideos(@RequestHeader(TICKET) String ticket,
                                         @RequestHeader(value = APP_CHANNEL, required = false) String channel,
                                         @RequestParam(value = "file", required = false) MultipartFile file) {

        SysUser sysUser = cache.getSysUser(ticket);
        if (sysUser != null){
            return StatusResponse.success(bizImportService.importVideos(channel, file));
        }

        return StatusResponse.error(ErrorCode.STAFF_HAS_NO_ROLE, "需要管理员");
    }


    @ApiOperation(value = "导入分类文章",httpMethod = "POST")
    @RequestMapping(value = "/import_articles", method = RequestMethod.POST, headers="content-type=multipart/form-data")
    public StatusResponse importArticles(@RequestHeader(TICKET) String ticket,
                                         @RequestHeader(value = APP_CHANNEL, required = false) String channel,
                                         @RequestParam(value = "file", required = false) MultipartFile file) {

        SysUser sysUser = cache.getSysUser(ticket);
        if (sysUser != null){
            return StatusResponse.success(bizImportService.importArticles(channel, file));
        }

        return StatusResponse.error(ErrorCode.STAFF_HAS_NO_ROLE, "需要管理员");
    }


    @ApiOperation(value = "导入指导文章",httpMethod = "POST")
    @RequestMapping(value = "/import_guide_articles", method = RequestMethod.POST, headers="content-type=multipart/form-data")
    public StatusResponse importGuideArticles(@RequestHeader(TICKET) String ticket,
                                              @RequestHeader(value = APP_CHANNEL, required = false) String channel,
                                              @RequestParam(value = "file", required = false) MultipartFile file) {
        SysUser sysUser = cache.getSysUser(ticket);
        if (sysUser != null){
            return StatusResponse.success(bizImportService.importPrivateArticles(channel, file));
        }

        return StatusResponse.error(ErrorCode.STAFF_HAS_NO_ROLE, "需要管理员");
    }

    @ApiOperation(value = "导入育儿宝典（StoreItem）的标签关系",httpMethod = "POST")
    @RequestMapping(value = "/import_storeitem_tags", method = RequestMethod.POST, headers="content-type=multipart/form-data")
    public StatusResponse importStoreItemTags(@RequestHeader(TICKET) String ticket,
                                              @RequestHeader(value = APP_CHANNEL, required = false) String channel,
                                              @RequestParam(value = "file", required = false) MultipartFile file) {

        SysUser sysUser = cache.getSysUser(ticket);
        if (sysUser != null){
            return StatusResponse.success(bizImportService.importStoreItemsTagsQuestions(channel, file));
        }

        return StatusResponse.error(ErrorCode.STAFF_HAS_NO_ROLE, "需要管理员");
    }

    @ApiOperation(value = "导入宝妈大比拼和每日tips数据（目前仅demo数据）",httpMethod = "POST")
    @RequestMapping(value = "/import_ptest", method = RequestMethod.POST)
    public StatusResponse importPtestDemo(@RequestHeader(TICKET) String ticket,
                                          @RequestHeader(value = APP_CHANNEL, required = false) String channel,
                                          @RequestParam(value = "file", required = false) MultipartFile file) {

        SysUser sysUser = cache.getSysUser(ticket);
        if (sysUser != null){
            return StatusResponse.success(bizImportService.importDemoPtestItems(channel, file ));
        }

        return StatusResponse.error(ErrorCode.STAFF_HAS_NO_ROLE, "需要管理员");
    }

    @ApiOperation(value = "导入每日任务模板",httpMethod = "POST")
    @RequestMapping(value = "/import_dailytask", method = RequestMethod.POST)
    public StatusResponse importDailyTask(@RequestHeader(TICKET) String ticket,
                                          @RequestHeader(value = APP_CHANNEL, required = false) String channel,
                                          @RequestParam(value = "file", required = false) MultipartFile file) {

        SysUser sysUser = cache.getSysUser(ticket);
        if (sysUser != null){
            return StatusResponse.success(bizImportService.importDailyTasks(channel, file));
        }

        return StatusResponse.error(ErrorCode.STAFF_HAS_NO_ROLE, "需要管理员");
    }

//    @ApiOperation(value = "导入家长每日观察",httpMethod = "POST")
//    @RequestMapping(value = "/import_p_observers", method = RequestMethod.POST)
//    public StatusResponse importParentObservers(@RequestHeader(TICKET) String ticket,
//                                          @RequestHeader(value = APP_CHANNEL, required = false) String channel,
//                                          @RequestParam(value = "file", required = false) MultipartFile file) {
//
//        SysUser sysUser = cache.getSysUser(ticket);
//        if (sysUser != null){
//            return StatusResponse.success();
//        }
//
//        return StatusResponse.error(ErrorCode.STAFF_HAS_NO_ROLE, "需要管理员");
//    }
//
//    @ApiOperation(value = "导入老师每日观察",httpMethod = "POST")
//    @RequestMapping(value = "/import_t_observers", method = RequestMethod.POST)
//    public StatusResponse importObservers(@RequestHeader(TICKET) String ticket,
//                                          @RequestHeader(value = APP_CHANNEL, required = false) String channel,
//                                          @RequestParam(value = "file", required = false) MultipartFile file) {
//
//        SysUser sysUser = cache.getSysUser(ticket);
//        if (sysUser != null){
//            return StatusResponse.success(obImportService.importTeacherObservers(channel, file));
//        }
//
//        return StatusResponse.error(ErrorCode.STAFF_HAS_NO_ROLE, "需要管理员");
//    }
}
